package it.tukano.swingdeco.containers;

import it.tukano.swingdeco.controls.JButtonExt;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JToolBar;

public class JToolBarExt extends JToolBar {

    /* Serial version of this class */
    private static final long serialVersionUID = 0;

    /**
     * Instance initializer
     */
    public JToolBarExt() {
    }

    /**
     * Set floatable property
     * @param on true to enable floating
     * @return this
     */
    public JToolBarExt floatable(boolean on) {
        setFloatable(on);
        return this;
    }

    /**
     * Add a set of components to this toolbar
     * @param components the components to add
     * @return this
     */
    public JToolBarExt append(Component... components) {
        for (int i = 0; i < components.length; i++) {
            Component component = components[i];
            add(component);
        }
        return this;
    }
    
    /**
     * Add a button and return this
     * @param label the label of the button
     * @param icon the icon of the button
     * @param callback the callback for the button
     * @return this
     */
    public JToolBarExt addJButton(String label, Icon icon, Runnable callback) {
        JButtonExt b =new JButtonExt();
        if(label != null) b.setText(label);
        if(icon != null) b.setIcon(icon);
        if(callback != null) {
            b.onAction(callback);
        }
        add(b);
        return this;
    }
}
